import { cloud } from '@hw-agconnect/cloud-server';
import { sys_role } from './sys_role'; // BookInfo是Server Model

// default是sys_role对象类型使用的存储区名
const collection = cloud.database({ zoneName: 'default' }).collection(sys_role);


export class SysRoleObj {
  method1(param1, param2) {
    console.info("this is message of info log");

    // do something here

    return { "simple": "example" };
  }

  query() {
    console.info("运行sys_role的query方法");
    return collection.query().get();

  }

  // 主键有的话就执行更新操作，主键不存在执行插入操作
  upset(sysRoles: sys_role[]) {
    return new Promise((resolve, reject) => {
      collection.upsert(sysRoles.map(book => sys_role.parseFrom(book)))
        .then(result => resolve({ result }))
        .catch(err => reject(err))
    });
  }
}
